package com.gitee.feizns.quickstart.ding.talk.api.v10.todo.users;

import com.aliyun.dingtalktodo_1_0.Client;
import com.aliyun.dingtalktodo_1_0.models.UpdateTodoTaskHeaders;
import com.aliyun.dingtalktodo_1_0.models.UpdateTodoTaskRequest;
import com.aliyun.teautil.models.RuntimeOptions;
import com.gitee.feizns.quickstart.ding.talk.client.Clients;
import lombok.SneakyThrows;

/**
 * 更新钉钉待办任务
 *
 * @link 更新钉钉待办任务 -> <a href="https://open.dingtalk.com/document/orgapp/updates-dingtalk-to-do-tasks">更新钉钉待办任务</a>
 * @author feizns
 * @since 2023/09/12
 */
public class PutTasks {

    /**
     * 执行
     * @param accessToken 访问令牌
     * @param unionId 联盟编号
     * @param taskId 任务编号
     * @param req 要求
     * @return boolean
     */
    @SneakyThrows
    public static boolean execute(String accessToken, String unionId, String taskId, UpdateTodoTaskRequest req) {
        Client client = Clients.get(Client.class);
        return client.updateTodoTaskWithOptions(unionId, taskId, req, headers(accessToken), new RuntimeOptions()).getBody().getResult();
    }

    /**
     * 执行
     * @param accessToken 访问令牌
     * @param unionId 联盟编号
     * @param taskId 任务编号
     * @return boolean
     */
    @SneakyThrows
    public static boolean execute(String accessToken, String unionId, String taskId) {
        UpdateTodoTaskRequest req = new UpdateTodoTaskRequest();
        req.setDone(Boolean.TRUE);
        return execute(accessToken, unionId, taskId, req);
    }

    /**
     * 请求头
     * @param accessToken 访问令牌
     * @return {@link UpdateTodoTaskHeaders}
     */
    public static UpdateTodoTaskHeaders headers(String accessToken) {
        UpdateTodoTaskHeaders headers = new UpdateTodoTaskHeaders();
        headers.xAcsDingtalkAccessToken = accessToken;
        return headers;
    }

}
